Page({
  data: {
    searchValue: "",
    banklists: [],
    banklist: [],
    selectbanklist: [],
  },
  searchBank(e) {
    console.log(e);
    console.log(this.data.selectbanklist);
    if (e.detail.length > 0) {
      let result = []
      this.data.banklists.filter(item => {
        if (item.bankName.indexOf(e.detail) !== -1) {
          result.push(item)
        }
      })
      console.log(result);
      this.setData({
        banklists: result,
        searchValue: e.detail
      })

    } else {
      this.setData({
        searchValue: e.detail
      })
      this.getlist()

    }

  },
  onChangeselebank(event) {
    console.log(event.detail);
    this.setData({
      selectbanklist: event.detail,
    });

    console.log(this.data.selectbanklist);

  },
  toggle(event) {
    // console.log(event);
    const {
      index
    } = event.currentTarget.dataset;

    const checkbox = this.selectComponent(`.checkboxes-${index}`);
    console.log(checkbox);
    checkbox.toggle();
    if (this.data.selectbanklist.length >= 5) {
      wx.showToast({
        title: '最多可选择五家！',
        icon: "none"
      })
    }
  },
  botton() {
    console.log(this.data.selectbanklist);
    let app = getApp();
    app.globalData.banklist = this.data.selectbanklist;
    // wx.switchTab({
    //   url: '/pages/financingapply/financingapply',
    // })
    wx.navigateBack({
      delta: -1
    })
  },
  async getlist() {
    const {
      data
    } = await getApp().globalData.request("/financing/getOrderedBanks", {city: '淮安市'}, "POST")
    console.log(data);
    this.setData({
      banklists: data.bankList
    })
  },
  onLoad: function (options) {
    this.setData({
      selectbanklist: getApp().globalData.banklist
    })
    // 获取银行列表
    this.getlist()
  },
  onShow: function () {
   
  },
})